package com.hejia.alauda.entity;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;

import org.apache.commons.lang3.StringUtils;

import com.hejia.alauda.Constants;

//import com.umpay.api.util.StringUtil;

/**
 * 支付订单，由于出现新手体验支付需求，提取支付订单对象，使支付流程模块化。
 * 
 * @author hyr
 *
 */
public class PayOrder extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2629325208773077073L;

	/**
	 * 支付订单号前缀
	 */
	public static final String PAY_NUMBER_PREFIX = "PN";

	/**
	 * 支付状态
	 * 
	 * @author hyr
	 *
	 */
	public enum Status {

		/**
		 * 未支付
		 */
		STATUS_UNPAY,

		/**
		 * 已确认支付
		 */
		STATUS_CONFIRM,

		/**
		 * 支付成功
		 */
		STATUS_PAID,

		/**
		 * 支付失败
		 */
		STATUS_FAILED,
	}

	/**
	 * 支付订单类型
	 * 
	 * @author hyr
	 *
	 */
	public enum Type {

		/**
		 * 新手体验支付订单
		 */
		ROOKIE_EXPERIENCE
	}

	@Column
	private String type; // 支付订单类型

	@Column
	private String payNumber; // 支付订单号

	@Column
	private String description; // 订单描述

	@Column
	private User user; // 用户

	@Column
	private BankCard bankCard; // 支付银行卡

	@Column
	private BigDecimal amount; // 支付金额

	@Column
	private String source; // 订单来源

	@Column
	private String payGateCode; // 支付网关代码

	@Column
	private String payGateStatus; // 从支付网关查询到的订单支付状态

	@Column
	private String status; // 交易状态

	@Column
	private Date notifyTime; // 支付结果通知时间

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getPayNumber() {
		return payNumber;
	}

	public void setPayNumber(String payNumber) {
		this.payNumber = payNumber;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public BankCard getBankCard() {
		return bankCard;
	}

	public void setBankCard(BankCard bankCard) {
		this.bankCard = bankCard;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		if ("IOS".equalsIgnoreCase(source)) {
			this.source = "IOS";
		} else if ("Android".equalsIgnoreCase(source)) {
			this.source = "Android";
		} else if ("H5".equalsIgnoreCase(source)) {
			this.source = "H5";
		} else if ("Web".equalsIgnoreCase(source)) {
			this.source = "Web";
		} else {
			this.source = source;
		}
	}

	public String getPayGateCode() {
		return payGateCode;
	}

	public void setPayGateCode(String payGateCode) {
		this.payGateCode = payGateCode;
	}

	public String getPayGateStatus() {
		return payGateStatus;
	}

	public void setPayGateStatus(String payGateStatus) {
		this.payGateStatus = payGateStatus;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getNotifyTime() {
		return notifyTime;
	}

	public void setNotifyTime(Date notifyTime) {
		this.notifyTime = notifyTime;
	}

	public String getStatusName() {
		String statusName = "未知状态";
		if (getStatus() != null) {
			switch (getStatus()) {
			case "STATUS_UNPAY":
				statusName = "未支付";
				break;
			case "STATUS_PAID":
				statusName = "支付成功";
				break;
			case "STATUS_FAILED":
				statusName = "支付失败";
				break;
			case "STATUS_CONFIRM":
				statusName = "已确认支付";
				break;
			default:
				break;
			}
		}
		return statusName;
	}

	public String getTypeName() {
		String typeName = "未知类型";
		if (getType() != null) {
			switch (getType()) {
			case "ROOKIE_EXPERIENCE":
				typeName = "新手体验支付订单";
				break;
			default:
				break;
			}
		}
		return typeName;
	}

	/**
	 * 获取支付网关名称
	 * 
	 * @return 支付网关名称
	 */
	public String getPayGateName() {

		if (StringUtils.isEmpty(this.payGateCode)) {
			return "连连支付";
		}

		String name = "";
		switch (this.payGateCode) {
		case Constants.PAYGATE_CODE_LLPAY:
			name = "连连支付";
			break;
		case Constants.PAYGATE_CODE_YEEPAY:
			name = "易宝支付";
			break;
		case Constants.PAYGATE_CODE_PAYECO:
			name = "易联支付";
			break;
		default:
			name = this.payGateCode;
			break;
		}
		return name;
	}

}
